/**
 * Copyright (c) 2024 - CARThunder
 * All Rights Reserved by Chengdu CARThunder Intelligent Technology Co., LTD and its affiliates.
 * You may not use, copy, distribute, modify, transmit in any form this file
 * except in compliance with CARThunder in writing by applicable law.
 *
 */

/**
 * file description.
 * @file    filename
 * @brief   brief function description.
 * @details detailed function description.
 * @version 1.0
 * @author  author_name
 * @date    last_modified_date
 *
 *      Edit History
 *      ----------------------------------------------------------------------------
 *      DATE                     NAME               DESCRIPTION
 *      2024-07-30              junjieluo         Create it.
 *
 */


package com.cart.musicdemo.view;

import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.cart.musicdemo.R;


/**
 * The type Loading init view.
 */
public class LoadingInitView extends RelativeLayout {
    private final AnimationDrawable mAnimationDrawable;

    /**
     * Instantiates a new Loading init view.
     *
     * @param context the context
     * @param attrs   the attrs
     */
    public LoadingInitView(Context context, AttributeSet attrs) {
        super(context, attrs);
        inflate(context, R.layout.view_init_loading, this);
        ImageView imgLoading = findViewById(R.id.img_init_loading);
        mAnimationDrawable = (AnimationDrawable) imgLoading.getDrawable();
    }

    /**
     * Start loading.
     */
    public void startLoading() {
        mAnimationDrawable.start();
    }

    /**
     * Stop loading.
     */
    public void stopLoading() {
        mAnimationDrawable.stop();
    }

    /**
     * Loading.
     *
     * @param isLoading 判断是否在加载中
     */
    public void loading(boolean isLoading) {
        if (isLoading) {
            startLoading();
        } else {
            stopLoading();
        }
    }
}
